//
//  HaveApplyView.m
//  Love trial1。0
//
//  Created by giantumbrella on 15/6/1.
//  Copyright (c) 2015年 赵娟. All rights reserved.
//

#import "HaveApplyView.h"
#import "CommonMacro.h"

@interface HaveApplyView ()

@property (nonatomic,strong) UIButton *pathButton;
@property (nonatomic,strong) UIImageView *activityImg;
@property (nonatomic,strong) UILabel *enterNum;
@property (nonatomic,strong) UIImageView *lessImg;
@property (nonatomic,strong) UILabel *lessNum;
@property (nonatomic,strong) UILabel *activityName;
@property (nonatomic,strong) UILabel *oldPrice;
@end
@implementation HaveApplyView

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if(self)
    {
       [self createView];
    }
    return self;
}

- (void)createView
{
    UITableView *tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, -15, SCREEN_WIDTH-20, SCREEN_HEIGHT*0.82)];
     [self addSubview:tableView];
    tableView.showsVerticalScrollIndicator = NO;
    tableView.dataSource = self;
    tableView.delegate = self;
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section

{
    
    return 6;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *ID = @"HaveApplyCell";
    UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
    if (cell==nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:ID];
    }
    //1.添加背景
    UIView *bgView = [[UIView alloc] initWithFrame:CGRectMake(15, 10, SCREEN_WIDTH-30, 260)];
    bgView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"试用首页商品底框@2x"]];
    //    bgView.backgroundColor = [UIColor blueColor];
    [cell addSubview:bgView];
    
    //公用坐标
    CGFloat labelY = 3;
    CGFloat Marggin = 5;

    //4.已参与
    self.enterNum = [[UILabel alloc] initWithFrame:CGRectMake(5, 0, bgView.frame.size.width*0.5, bgView.frame.size.height*0.15)];
    //    self.enterNum.backgroundColor = [UIColor redColor];
    self.enterNum.textColor = UIColorWithRGBA(189, 187, 189, 1);
    self.enterNum.font = [UIFont fontWithName:nil size:12];
    [bgView addSubview:self.enterNum];
    self.enterNum.text = @"以参与：396";
    self.enterNum.textColor = UIColorWithRGBA(126, 194, 249, 1);
    self.enterNum.font = [UIFont boldSystemFontOfSize:18];
    
    //6.大背景
    self.activityImg = [[UIImageView alloc] initWithFrame:CGRectMake(3, self.enterNum.frame.origin.y+self.enterNum.frame.size.height+15, bgView.frame.size.width-6, bgView.frame.size.height*0.55)];
    [bgView addSubview:self.activityImg];
    self.activityImg.image = [UIImage imageNamed:@"新品上架"];
    
    //5.通过签章
    self.pathButton = [[UIButton alloc] initWithFrame:CGRectMake(bgView.frame.size.width*0.73, labelY+5, bgView.frame.size.width*0.25, bgView.frame.size.width*0.25)];
    [self.pathButton setBackgroundImage:[UIImage imageNamed:@"通过-章"] forState:UIControlStateNormal];
    //    self.pathButton.backgroundColor = [UIColor redColor];
    [bgView addSubview:self.pathButton];
    
    //7.1剩余
    self.lessImg = [[UIImageView alloc] initWithFrame:CGRectMake(self.activityImg.frame.origin.x+Marggin*2, self.activityImg.frame.origin.y-6, self.enterNum.frame.size.width*0.33, self.enterNum.frame.size.height*1.6)];
    self.lessImg.image = [UIImage imageNamed:@"剩余@2x"];
    [bgView addSubview:self.lessImg];
    
    //7.2剩余数量
    self.lessNum = [[UILabel alloc] initWithFrame:CGRectMake(self.lessImg.frame.origin.x, self.lessImg.frame.origin.y+10, self.lessImg.frame.size.width, self.lessImg.frame.size.height)];
    self.lessNum.textAlignment = NSTextAlignmentCenter;
    self.lessNum.textColor = UIColorWithRGBA(255, 255, 255, 1);
    self.lessNum.font = [UIFont boldSystemFontOfSize:18];
    [bgView addSubview:self.lessNum];
    self.lessNum.text = @"50";
    self.lessNum.font = [UIFont boldSystemFontOfSize:20];
    
    //8.产品名称
    self.activityName = [[UILabel alloc] initWithFrame:CGRectMake(self.activityImg.frame.origin.x+6, self.activityImg.frame.origin.y+self.activityImg.frame.size.height,bgView.frame.size.width*0.77, bgView.frame.size.width*0.16)];
    [self.activityName setAdjustsFontSizeToFitWidth:YES];
    [bgView addSubview:self.activityName];
    self.activityName.textColor = UIColorWithRGBA(59, 59, 59, 1);
    self.activityName.font = [UIFont fontWithName:nil size:16];
    self.activityName.text = @"原产美国雅培精装婴幼儿奶粉试用";
    
    //9.老价钱
    self.oldPrice = [[UILabel alloc] initWithFrame:CGRectMake(bgView.frame.size.width*0.8, self.activityName.frame.origin.y, bgView.frame.size.width*0.2, self.activityName.frame.size.height)];
    self.oldPrice.textColor = UIColorWithRGBA(234, 76, 114, 1);
    self.oldPrice.font = [UIFont fontWithName:nil size:20];
    self.oldPrice.font = [UIFont boldSystemFontOfSize:20];
    [bgView addSubview:self.oldPrice];
    self.oldPrice.text =@"￥395";
    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return  260;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    if ([self.delegate respondsToSelector:@selector(applySideBar:didSelectAtIndex:)])
    {
        [self.delegate applySideBar:self didSelectAtIndex:indexPath.row];
    }
   
}
@end
